package com.jiangyao.controller;

import com.jiangyao.common.ApiResult;
import com.jiangyao.model.dto.backend.CoursewareDTO;
import com.jiangyao.model.dto.backend.CoursewareListPageDTO;
import com.jiangyao.model.vo.backend.CoursewareDetailVO;
import com.jiangyao.model.vo.backend.CoursewareListVO;
import com.jiangyao.service.CoursewareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 课件 前端控制器
 * </p>
 *
 * @author yangyongchuan
 * @since 2020-08-20
 */
@RestController
@RequestMapping("/courseware")
@Api(tags = "课件管理")
public class CoursewareController extends BaseController {

	@Autowired
	private CoursewareService coursewareService;

	/**
	 * 获取课件列表
	 *
	 * @param listPageDTO 列表DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取课件列表")
	@PostMapping("/list")
	public ApiResult<CoursewareListVO> getListPage(@Validated({CoursewareListPageDTO.ListPage.class}) @RequestBody CoursewareListPageDTO listPageDTO) {
		return ApiResult.success(coursewareService.getListPage(listPageDTO));
	}

	/**
	 * 增加课件
	 *
	 * @param coursewareDTO 增加DTO
	 * @return 结果
	 */
	@ApiOperation(value = "增加课件")
	@PostMapping("/add")
	public ApiResult<String> add(@Validated({CoursewareDTO.Add.class}) @RequestBody CoursewareDTO coursewareDTO) {
		coursewareService.add(coursewareDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 编辑课件
	 *
	 * @param coursewareDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑课件")
	@PostMapping("/edit")
	public ApiResult<String> edit(@Validated({CoursewareDTO.Edit.class}) @RequestBody CoursewareDTO coursewareDTO) {
		coursewareService.edit(coursewareDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 编辑课件状态（启用、禁用）
	 *
	 * @param coursewareDTO 编辑DTO
	 * @return 结果
	 */
	@ApiOperation(value = "编辑课件状态（启用、禁用）", notes = "必填字段：coursewareIdList、status")
	@PostMapping("/editStatus")
	public ApiResult<String> editStatus(@Validated({CoursewareDTO.Delete.class}) @RequestBody CoursewareDTO coursewareDTO) {
		coursewareService.editStatus(coursewareDTO);
		return new ApiResult<>("ok");
	}

	/**
	 * 获取课件详情
	 *
	 * @param coursewareDTO 请求DTO
	 * @return 结果
	 */
	@ApiOperation(value = "获取课件详情", notes = "必填字段：coursewareId")
	@PostMapping("/detail")
	public ApiResult<CoursewareDetailVO> detail(@Validated({CoursewareDTO.Detail.class}) @RequestBody CoursewareDTO coursewareDTO) {
		return new ApiResult<>(coursewareService.getDetail(coursewareDTO));
	}


}

